/**
 * @description:
 * @Author: zyt
 */

import com.check.ui.CheckRuleStage;
import com.check.utils.*;
import com.github.crab2died.ExcelUtils;
import javafx.application.Application;
import javafx.stage.Stage;
import org.junit.Test;

import javax.rmi.CORBA.Util;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

public class test extends Application {

    public static void main(String[] args) throws IOException {

        launch(args);
    }



    @Override
    public void start(Stage primaryStage) {
        // StageModal stageModa = new StageModal("正在检查");
        CheckRuleStage stage = new CheckRuleStage();
        stage.show();
    }

    @Test
    public void listSetTest(){
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("@");
        arrayList.add("B");
        arrayList.add("A");
        arrayList.add("C");
        arrayList.add("D");
        arrayList.set(0, "New A");
        System.out.println(arrayList);
    }

    @Test
    public void testCheckRule() throws IOException {
        List lists = ExcelUtils.getInstance().readExcel2List("D:\\腾讯软件\\腾讯数据\\2295832469\\FileRecv\\第6批总表检查20200802.xlsx");
        lists.stream().forEach(System.out::println);
    }

    @Test
    public void testInExcel() throws IOException {
        List<List<String>> lists = ExcelUtils.getInstance().readExcel2List("C:\\Users\\22958\\Desktop\\报错文件\\抽检1110.xls");
        DataUtil.dataFormat(lists);
        System.out.println(lists.get(0).size());
        System.out.println(lists.get(1).size());
        lists.stream().forEach(System.out::println);
    }

    @Test
    public void testCopy(){
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        List<String> list1 = new ArrayList<>(list.size());

        System.out.println(list.size());
        System.out.println(list1.size());
        Collections.copy(list,list1);
        System.out.println(list1);
        System.out.println(list);
    }

    @Test
    public void regTest(){
        Rule rule = new Rule();
        System.out.println(rule.matches("^[\\d]{17}[\\d|X][1-7][1-4]$", "36012119701121001345"));

    }

    @Test
    public void timeTest(){
        System.out.println(System.currentTimeMillis()+(1000L*60L*60L*24L*30L));

    }

    @Test
    public void logTest(){
        LogUtils.appendLog("张");
    }

    @Test
    public void dirTest(){
        final Properties properties = System.getProperties();
        properties.forEach((k,v)-> System.out.println(k+":"+v));
    }

    @Test
    public void trimTest(){

        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add(" 中间件 是快快快 ");
        arrayList.add(" 中间件 是 快快 快");
        arrayList.add(" 中间件 是快 快快");
        arrayList.add(" 中间件 是快快快 ");


        String str = StringUtils.trim("zhang san -- jj " +
                "" +
                "");
        System.out.println(str);
        List<String> lists = arrayList.stream().map(s ->StringUtils.trim(s)).collect((Collectors.toList()));

        System.out.println(lists);

    }

    @Test
    public void idTest(){
        System.out.println(Rule.IdentityCardVerification("332523195810073328"));
        System.out.println(Rule.IdentityCardVerification("332523195208243320"));
        System.out.println(Rule.IdentityCardVerification("332523196508023324"));
    }

    @Test
    public void addTest(){
        List<String> list1 = new ArrayList<>();
        list1.add("1");
        list1.add("2");
        list1.add("3");
        List<String> list2 = new ArrayList<>();
        list2.add("4");
        list2.add("5");
        list2.add("6");
        list1.addAll(list2.subList(1,list2.size()));
        System.out.println(list1);
    }

    private String check(Rule rule, List<List<String>> errList, List<String> list, String str, AtomicReference<Boolean> b, String k1) {
        StringBuffer message = new StringBuffer();

        if("邮箱".equals(k1)){
            if (!rule.emailRule(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("邮箱;");
            }
        }
        if("手机号".equals(k1)){
            if (!rule.phoneRule(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("手机号;");
            }
        }

        if("身份证".equals(k1)){
            if (!Rule.IdentityCardVerification(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("身份证;");
            }
        }

        if("唯一性".equals(k1)){
            if (!rule.isOne(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("唯一性;");
            }
        }
        if("小数".equals(k1)){
            if (!rule.isDoubleNum(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("小数;");
            }
        }

        if("整数".equals(k1)){
            if (!rule.isIntNum(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("整数;");
            }
        }

        if("必填项".equals(k1)){
            if (!rule.isNotNull(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("必填项;");
            }
        }

        if("手机加座机".equals(k1)){
            if (!rule.phoneAllRule(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("手机加座机;");
            }
        }

        if("日期".equals(k1)){
            if (!rule.isDate(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("日期;");
            }
        }

        if("日期加时间".equals(k1)){
            if (!rule.isDateTime(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("日期加时间;");
            }
        }

        if("数字加字母".equals(k1)){
            if (!rule.isNumAndAbc(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("数字加字母;");
            }
        }

        if("非中文".equals(k1)){
            if (!rule.isNotAllChinese(str)) {
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("非中文;");
            }
        }

        // 根据配置文件的自定义检查
        Properties properties = PropertiesUtils.getPropertiesValue("/checkRule.properties");
        if(properties.containsKey(k1)){
            final String ruleValue = properties.getProperty(k1);
            if(!rule.matches(ruleValue,str)){
                if(b.get()){
                    errList.add(list);
                    b.set(false);
                }
                message.append("非"+k1+";");
            }
        }
        return message.toString();
    }
}


